package personal.xjl._23java2studentdemo.mapper;

import org.apache.ibatis.annotations.*;
import personal.xjl._23java2studentdemo.model.Course;
import personal.xjl._23java2studentdemo.model.Student;
import personal.xjl._23java2studentdemo.model.Teacher;

import java.util.List;

@Mapper// 标识这是一个MyBatis的Mapper接口
public interface CourseMapper {
    @Select("select * from course")
    @Results({
            @Result(column = "teacher_id",property = "teacher",javaType = Teacher.class,
                    one = @One(select = "personal.xjl._23java2studentdemo.mapper.TeacherMapper.selectById"))
    })
    List<Course> selectAll();

    @Select("select * from course where id=#{id}")
    Course selectById(int id);

    // 删除课程
    @Delete("delete from course where id=#{id}")
    public int deleteById(int id);

    // 新增课程
    @Insert("insert into course(name,teacher_id) values (#{name},#{teacher_id})")
    int insert(Course course);

    // 修改
    @Update("update course set name=#{name},teacher_id=#{teacher_id} where id=#{id}")
    int update(Course course);

    @Select("select * from course limit #{fromIndex},#{pageSize}")
    @Results({
            @Result(column = "teacher_id",property = "teacher",javaType = Teacher.class,
                    one = @One(select = "personal.xjl._23java2studentdemo.mapper.TeacherMapper.selectById"))
    })
    List<Course> selectByPage(int fromIndex, int pageSize);
}